<?php

class Admin_Form_User extends Zend_Form
{
    public function init()
    {
        $this->setName('User');
		$userId = new Zend_Form_Element_Hidden("UserID");
		$userId->addFilter('Int');
		
		$userName = new Zend_Form_Element_Text("UserName");
		$userName->setLabel("User Name")
				 ->setRequired(true)
				 ->setAttrib("size", "40")
				 ->setAttrib("style", "width:370px")
				 ->setAttrib("maxlength", "50")
				 ->addFilter("StripTags")	
				 ->addFilter("StringTrim")
				 ->addValidator("NotEmpty");
				 
		$userEmail = new Zend_Form_Element_Text("UserEmail");
		$userEmail->setLabel("User Email")
				  ->setRequired(true)
				  ->setAttrib("size", "40")
				  ->setAttrib("style", "width:370px")
				  ->setAttrib("maxlength", "50")
				  ->addFilter("StripTags")
				  ->addFilter("StringTrim")
				  ->addValidator("NotEmpty")
				  ->addValidator('EmailAddress'); 
				  
		$userLoginName = new Zend_Form_Element_Text("UserLoginName");
		$userLoginName->setLabel("User Login Name")
					  ->setRequired(true)
					  ->setAttrib("style", "width:204px")
					  ->setAttrib("size", "30")
					  ->setAttrib("maxlength", "30")
					  ->addFilter("StripTags")
					  ->addFilter("StringTrim")
					  ->addValidator("NotEmpty");		
					  
		$userPassword = new Zend_Form_Element_Password('UserPassword');		
		$userPassword->setLabel("Password")
				 ->setRequired(true)
				 ->setAttrib("style", "width:204px")
				 ->setAttrib("size", "30")
				 ->setAttrib("maxlength", "30")
				 ->addFilter("StripTags")
				 ->addFilter("StringTrim")
				 ->addValidator('StringLength', false, array(8,30));
				 
		$userConfirmPassword = new Zend_Form_Element_Password('UserConfirmPassword');		
		$userConfirmPassword->setLabel("Confirm Password")
				 ->setRequired(true)
				 ->setAttrib("size", "30")
				 ->setAttrib("style", "width:204px")
				 ->setAttrib("maxlength", "30")
				 ->addFilter("StripTags")
				 ->addFilter("StringTrim")
				 ->addValidator('StringLength', false, array(8,30))
				 ->addValidator('Identical', false, array('token' => 'UserPassword'));
				 				 						
		$userRole = new Zend_Form_Element_Select("UserRole"); 						
		$userRole->setLabel("Roles")
			 ->setAttrib("style", "width:100px")
			 ->setMultiOptions(array(Admin_Model_DbTable_User::USER_ADMIN => Admin_Model_DbTable_User::USER_ADMIN,
								Admin_Model_DbTable_User::USER_JTEPM => Admin_Model_DbTable_User::USER_JTEPM,
								Admin_Model_DbTable_User::USER_TRANSLATOR=> Admin_Model_DbTable_User::USER_TRANSLATOR,
								Admin_Model_DbTable_User::USER_CLIENT => Admin_Model_DbTable_User::USER_CLIENT))
			->addFilter('StripTags')
			->addFilter('StringTrim');
			
		$sourcelanguageId = new Zend_Form_Element_MultiCheckbox('SourcelanguageID');		
		$sourcelanguageId->setLabel('Source languageID')
				 ->setName("SourcelanguageID[]")
				 ->setRequired(true)
				 ->setRegisterInArrayValidator(false)
				 ->addFilter('StripTags')
			     ->addFilter('StringTrim');
				 
		$sourcelanguageId->setDecorators(array(
			'ViewHelper',
			'Description',
			array( array('elementDiv' => 'HtmlTag'), array('tag' => 'div', 'style'=>'width: 400px; height:167px; overflow:scroll; border: 1px solid #7F9DB9;', "id" => "TranslatorTargetlanguageID")),
			'Errors',
			array( array('dd' => 'HtmlTag'), array('tag' => 'dd')),			
			array('Label', array('tag' => 'dt')),
		));		 
		
		$languageMapper = new Admin_Model_Mapper_Language();			 
		$sourceListLanguage = $languageMapper->getSourceLanguageActive();		 
		foreach($sourceListLanguage as $language){
			$sourcelanguageId->addMultiOption($language->getLanguageId(), $language->getLanguageName());			
		}		
						
		$userIsActive = new Zend_Form_Element_CheckBox("UserIsActive");	
		$userIsActive->setLabel("User Is Active")
					 ->setUncheckedValue("N")
					 ->setCheckedValue("Y")
					 ->setValue("Y");
					 
		$submit = new Zend_Form_Element_Submit("submit");
		$submit->setAttrib("id","submitbutton")
			   ->setAttrib("style","width:80px");
		
		/*$hash = new Zend_Form_Element_Hash('hash', 'no_csrf_foo', array('salt' => '~!@#$%^&*D@ngha123456')); 
		$hash->setDecorators(array( 
                     array('ViewHelper', array('helper' => 'formHidden')) 
                 ));
		*/		 
				 
		$this->addElements(array($userName, $userEmail, $userLoginName, $userPassword, $userConfirmPassword, $userRole, $sourcelanguageId, $userIsActive, $submit, $userId, /*$hash*/));
    }


}

